package org.rui.rpc.enums;

import lombok.Getter;

/**
 * @author: linweirui
 * @date: 2024/12/09 9:17
 */
@Getter
public enum ProtocolMessageTypeEnum {
    REQUEST(0),
    RESPONSE(1),
    HEART_BEAT(2),
    OTHERS(3);
    private final int key;

    ProtocolMessageTypeEnum(int key) {
        this.key = key;
    }

    /**
     * 根据枚举值获取枚举类型
     *
     * @param value
     * @return
     */
    public static ProtocolMessageTypeEnum getMessageTypeByValue(int value) {
        for (ProtocolMessageTypeEnum typeEnum : ProtocolMessageTypeEnum.values()) {
            if (typeEnum.key == value) {
                return typeEnum;
            }
        }
        return null;
    }
}
